package cn.com.yusys.yusp.admin.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.zaxxer.hikari.HikariDataSource;

import cn.com.yusys.yusp.admin.domain.DBProperties;

@Configuration
@EnableTransactionManagement
public class DBConfig {
	@Autowired
	private DBProperties env;

	@Bean(destroyMethod = "close")
	public DataSource dataSource() {
		HikariDataSource dataSource= new HikariDataSource();
		dataSource.setDriverClassName(env.getDriverClassName().trim());
		dataSource.setJdbcUrl(env.getUrl().trim());
		dataSource.setUsername(env.getUsername().trim());
		try {
			dataSource.setPassword(env.getPassword().trim());
//			dataSource.setPassword(ConfigTools.decrypt(env.getPublickey().trim(), env.getPassword().trim()));
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		return dataSource;
	}

}